import java.util.ArrayList;
import java.util.Scanner;
public class theHappyNum {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        System.out.println(isHappyNum(n));
    }
    public static boolean isHappyNum(int n){
        ArrayList<Integer> list=new ArrayList<>();
        int tmp=0;
        while(tmp!=1){
            if(tmp!=0) n=tmp;
            tmp=0;
            while(n!=0){
                tmp+=(int)Math.pow(n%10,2);
                n/=10;
            }
            if(list.contains(tmp))return false;
            list.add(tmp);
        }
        return true;
    }
}
